package tests;

import common.Utils;
import org.openqa.selenium.By;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-03-30
 * Time:21:51
 */
public class RegistrationPage extends Utils {
    public static String url="http://127.0.0.1:9580/sign-up.html";
    public RegistrationPage() {
        super(url);
    }
    //查看是否有注册页面
    public void RegisterPageRight() throws InterruptedException {
        //通过查看页面元素是否存在来检查页面加载是否成功
        driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(2) > label"));
        driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(3) > label"));
        driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(4) > label"));
        driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(5) > label"));
        driver.findElement(By.cssSelector("#username"));
        driver.findElement(By.cssSelector("#nickname"));
        driver.findElement(By.cssSelector("#password"));
        driver.findElement(By.cssSelector("#passwordRepeat"));
        driver.findElement(By.cssSelector("#submit"));

    }
    //注册成功
    public void RegisterSuc() throws InterruptedException {
        //清除原有的用户名和密码
        driver.navigate().refresh();
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("#username")).sendKeys("xiaoyuannn");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("xiaoyuannn");
        driver.findElement(By.cssSelector("#password")).sendKeys("1234");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("1234");
        driver.findElement(By.cssSelector("#policy")).click();
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(3000);
        //检查点击确定之后是否注册成功，进入登录页
        String expect="用户登录";
        String text=driver.findElement(By.cssSelector("body > div > div > div > div:nth-child(1) > div > div.card.card-md > div")).getText();
        assert expect.equals(text);
        Thread.sleep(3000);
    }
    //注册失败
    //1.新密码和旧密码不一致，提示请检查确认密码
    public void RegisterFail() throws InterruptedException {
        //清除原有的用户名和密码
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#username")).sendKeys("xiaoyuannn");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("xiaoyuannn");
        driver.findElement(By.cssSelector("#password")).sendKeys("123");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("1234");
        driver.findElement(By.cssSelector("#policy")).click();
        driver.findElement(By.cssSelector("#submit")).click();
        //提示请检查确认密码
        String text=driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(5) > div > div")).getText();
        String expect="请检查确认密码";
        assert expect.equals(text);
        //还在原来页面
        String except1="用户注册";
        String res=driver.findElement(By.cssSelector("#signUpForm > div > h2")).getText();
        assert res.equals(except1);
        Thread.sleep(3000);
        driver.navigate().refresh();
        Thread.sleep(3000);
    }
    //2.全为空
    public void RegisterFailNull() throws InterruptedException {
        //清除原有的用户名和密码
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#policy")).click();
        driver.findElement(By.cssSelector("#submit")).click();
        String except1="昵称不能为空";
        String res1=driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(2) > div")).getText();
        assert res1.equals(except1);
        String except2="密码不能为空";
        String res2=driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(4) > div > div")).getText();
        assert res2.equals(except2);
        String text=driver.findElement(By.cssSelector("#signUpForm > div > div:nth-child(5) > div > div")).getText();
        String expect="请检查确认密码";
        assert expect.equals(text);
        Thread.sleep(3000);
        driver.navigate().refresh();
        Thread.sleep(3000);
    }
}
